#! /bin/bash

FOLDER="src/main/scala/sa4"
SKELETON="src/main/scala/sa4/Skeleton.scala"
WEBINF="src/main/webapp/WEB-INF/web.xml"

echo "Insert the name of your application, if it doesn't exists a new project will be created"

read name

NEWWEB="src/main/webapp/WEB-INF/web2.xml"
cp $WEBINF $NEWWEB

if [ -f "${FOLDER}/${name}.scala" ]
then
	sed -e "s/>sa4.*</>sa4.$name</g" $WEBINF > $NEWWEB
	cp $NEWWEB $WEBINF
	rm $NEWWEB
	./sbt compile container:start shell
else
	NEWAPP="src/main/scala/sa4/${name}.scala"
	cp $SKELETON $NEWAPP

	sed -e "s/Skeleton/$name/g" $SKELETON > $NEWAPP
	sed -e "s/>sa4.*</>sa4.$name</g" $WEBINF > $NEWWEB
	cp $NEWWEB $WEBINF
	rm $NEWWEB
	./sbt compile container:start shell
fi